//
//  ScenicDetailVC.m
//  ImGuider
//
//  Created by llt on 2017/8/29.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "ScenicDetailVC.h"

@interface ScenicDetailVC ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

// 景点名称
@property (weak, nonatomic) IBOutlet UIView *nameView;
@property (weak, nonatomic) IBOutlet UILabel *nameDescribeLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

// 电话
@property (weak, nonatomic) IBOutlet UIView *phoneView;
@property (weak, nonatomic) IBOutlet UILabel *phoneDescribeLabel;
@property (weak, nonatomic) IBOutlet UIButton *phoneBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *phoneHeight;

// 网站
@property (weak, nonatomic) IBOutlet UIView *websiteView;
@property (weak, nonatomic) IBOutlet UILabel *websiteDescribeLabel;
@property (weak, nonatomic) IBOutlet UIButton *websiteBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *websiteHeight;

// 用时参考
@property (weak, nonatomic) IBOutlet UIView *elapsedView;
@property (weak, nonatomic) IBOutlet UILabel *elapsedDescribeLabel;
@property (weak, nonatomic) IBOutlet UIButton *elapsedBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *elapsedHeight;

// 门票
@property (weak, nonatomic) IBOutlet UIView *ticketsView;
@property (weak, nonatomic) IBOutlet UILabel *ticketsDescribeLabel;
@property (weak, nonatomic) IBOutlet UILabel *ticketsLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ticketsHeight;


// 开放时间
@property (weak, nonatomic) IBOutlet UIView *openTimeView;
@property (weak, nonatomic) IBOutlet UILabel *openTimeDescribeLabel;
@property (weak, nonatomic) IBOutlet UILabel *openTimeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *openTimeHeight;


// 地址
@property (weak, nonatomic) IBOutlet UIView *addressView;
@property (weak, nonatomic) IBOutlet UILabel *addressDescribeLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *addressHeight;

@end

@implementation ScenicDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.barBGAlpha = 0;
    
    self.subScrollView = self.scrollView;
    
    self.elapsedHeight.constant = 0;
    self.elapsedView.hidden = YES;
    
    self.phoneDescribeLabel.text = MYLocalizedString(@"SITELIST_PHONE", nil);
    self.websiteDescribeLabel.text = MYLocalizedString(@"SITELIST_WEBSITE", nil);
    self.ticketsDescribeLabel.text = MYLocalizedString(@"SITELIST_TICKET", nil);
    self.openTimeDescribeLabel.text = MYLocalizedString(@"SITELIST_OPENINGHOURS", nil);
    self.addressDescribeLabel.text = MYLocalizedString(@"SITELIST_ADDRESS", nil);
    
    [self configInfo];
}


-(void)configInfo {
    
   
    self.nameLabel.text = self.scenic.ename;
    self.nameDescribeLabel.text = self.scenic.viewname;
    
    
    if (self.scenic.telephone.length > 0) {
        
        [self.phoneBtn setTitle:self.scenic.telephone forState:UIControlStateNormal];
    }else {
        self.phoneHeight.constant = 0;
        self.phoneView.hidden = YES;
    }
    
    if (self.scenic.website.length > 0) {
        [self.websiteBtn setTitle:self.scenic.website forState:UIControlStateNormal];
    }else {
        self.websiteHeight.constant = 0;
        self.websiteView.hidden = YES;
    }
    
    CGFloat defaultHeight;
    
    NSString * str = [self.scenic.ticket stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if (str.length > 0) {
        self.ticketsLabel.text = self.scenic.ticket;
        self.ticketsHeight.constant = [IGUtils getHeightWithText:self.scenic.ticket width:SCREEN_WIDTH - 38 lineSpacing:0 font:Font(14) defaultHeight:&defaultHeight] + 47;
    }else {
        self.ticketsHeight.constant = 0;
        self.ticketsView.hidden = YES;
    }
    
    NSString * str1 = [self.scenic.openinfo stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if (str1.length >0) {
        self.openTimeLabel.text = self.scenic.openinfo;
        self.openTimeHeight.constant = [IGUtils getHeightWithText:self.scenic.openinfo width:SCREEN_WIDTH - 38 lineSpacing:0 font:Font(14) defaultHeight:&defaultHeight] + 47;
    }else {
        self.openTimeHeight.constant = 0;
        self.openTimeView.hidden = YES;
    }
    
    NSString * str2 = [self.scenic.address stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if (str2.length > 0) {
        self.addressLabel.text = self.scenic.address;
        self.addressHeight.constant = [IGUtils getHeightWithText:self.scenic.address width:SCREEN_WIDTH - 38 lineSpacing:0 font:Font(14) defaultHeight:&defaultHeight] + 47;
    }else {
        self.addressHeight.constant = 0;
        self.addressView.hidden = YES;
    }
    
}

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat offsetY = scrollView.contentOffset.y;
    if (!self.canScroll) {
        [scrollView setContentOffset:CGPointZero];
    }
    
    if (offsetY < 0 ) {
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"kLeaveTopNtf" object:@1];
        self.canScroll = NO;
        scrollView.contentOffset = CGPointZero;
    }
}


- (IBAction)navAction:(id)sender {
    
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.scenic.lat.doubleValue, self.scenic.lng.doubleValue);
    [IGUtils tractficToLocation:transformFromWGSToGCJ(coordinate, self.scenic.country) vc:self];
}
- (IBAction)phoneAction:(id)sender {
    NSString * phoneNum = [[self.scenic.telephone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString * str = [NSString stringWithFormat:@"tel://%@",phoneNum];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
- (IBAction)websiteAction:(id)sender {
    
    NSString * str = [self.scenic.website stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSURL *url= [NSURL URLWithString:str];
    [[UIApplication sharedApplication] openURL:url];
}

@end
